#coding:utf-8
import ctypes,os,hashlib,time
SVN_PATH= ""
def SetSVN_PATH(path):
    SVN_PATH = path
def GetSVN_PATH():
    return SVN_PATH

def GetFileSize(file):#File Object
    file.seek(0, os.SEEK_END)
    fileLength = file.tell()
    file.seek(0, 0)
    return fileLength
def GetParentFloder(path):
    index = path.rindex("\\")
    if index == -1:
        return path
def GetFileName(fileFullPath):
    index = fileFullPath.rindex('\\')
    if index == -1:
        return fileFullPath
    else:
        return fileFullPath[index+1:]

def txt_(start_str, end, html):
    start = html.find(start_str)
    if start >= 0:
        start += len(start_str)
        end = html.find(end, start)
        if end >= 0:
            return html[start:end].strip()
def GetFileCMTime(file_path,formats=False):
    mtime = time.ctime(os.path.getmtime(file_path))
    ctime = time.ctime(os.path.getctime(file_path))
    if formats == True:
        return time.ctime(ctime),time.ctime(mtime)
    else:
        return ctime,mtime
def GetFileMd5(filename):
    if not os.path.isfile(filename):
        return
    myhash = hashlib.md5()
    f = file(filename,'rb')
    while True:
        b = f.read(8096)
        if not b :
            break
        myhash.update(b)
    f.close()
    return myhash.hexdigest()
#获取目录列表
def gci(filepath):
    floder =[]
    file=[]
    files = os.listdir(filepath)
    for fi in files:

        fi_d = os.path.join(filepath,fi)
        if os.path.isdir(fi_d):
            floder.append(fi_d)
            gci(fi_d)
        else:
            #print os.path.join(filepath,fi_d)
            file.append(os.path.join(filepath,fi_d))
    return floder,file
def Ret_Md5(strs):
    hashs = hashlib.md5()
    hashs.update(strs)
    return hashs.hexdigest()

if __name__ == '__main__':
    import uuid
    print Ret_Md5(str(uuid.uuid1()))





#因为代码被废弃所以用不上
'''
WM_SYSCOMMAND = 274
SC_MINIMIZE = 61472
MOD_ALT = 1
GENERIC_READ = -2147483648
GENERIC_WRITE = 1073741824
FILE_SHARE_READ = 1
FILE_SHARE_WRITE = 2
FILE_SHARE_DELETE = 4
FILE_FLAG_BACKUP_SEMANTICS = 33554432
OPEN_EXISTING = 3
FILE_NOTIFY_CHANGE_FILE_NAME = 1
FILE_NOTIFY_CHANGE_DIR_NAME = 2
FILE_NOTIFY_CHANGE_ATTRIBUTES = 4
FILE_NOTIFY_CHANGE_SIZE = 8
FILE_NOTIFY_CHANGE_LAST_WRITE = 16
FILE_NOTIFY_CHANGE_LAST_ACCESS = 32
FILE_NOTIFY_CHANGE_CREATION = 64
FILE_NOTIFY_CHANGE_SECURITY = 256
FILE_ACTION_ADDED = 1
FILE_ACTION_REMOVED = 2
FILE_ACTION_RENAMED_NEW_NAME = 5
FILE_ACTION_RENAMED_OLD_NAME = 4
FILE_ACTION_MODIFIED = 3
class _FILE_NOTIFY_INFORMATION(ctypes.Structure):
    _fields_ = [("NextEntryOffset",ctypes.c_int),
                ('Action',ctypes.c_int),
                ("FileNameLength",ctypes.c_int),
                ("FileName",ctypes.c_byte * 1024)]
class OVERLAPPED(ctypes.Structure):
    _fields_ = [('ternal',ctypes.c_int),
                ('ternalHigh',ctypes.c_int),
                ('low32',ctypes.c_int),
                ('hight32',ctypes.c_int),
                ('e_handle',ctypes.c_int)]

#C的Byte类型转换为utf-8的的文本
def C_ByteArrayToString(Arrays):
        ret = ""
        for i in Arrays:
            if i != 0 :
                try:
                    ret += unichr(i)
                except:
                    print i
                    ret += ""
        return ret

'''

